package com.gitee.easyopen.server;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gitee.easyopen.ApiConfig;
import com.gitee.easyopen.interceptor.ApiInterceptor;
import com.gitee.easyopen.server.interceptor.LogInterceptor;
import com.gitee.easyopen.support.ApiController;
import com.gitee.easyopen.util.RSAUtil;
import com.gitee.easyopen.util.RSAUtil.KeyStore;

@Controller
@RequestMapping(value = "/api")
public class IndexController extends ApiController {

    @Override
    protected void initApiConfig(ApiConfig apiConfig) {
        apiConfig.setShowDoc(true); // 显示文档页面
        // 配置国际化消息
        apiConfig.getIsvModules().add("i18n/isv/goods_error");

        // 配置秘钥键值对
        Map<String, String> appSecretStore = new HashMap<String, String>();
        appSecretStore.put("test", "123456");

        KeyStore keyStore = RSAUtil.createKeys(1024);
        String publicKey = keyStore.getPublicKey(); // 公钥固定不变
        System.out.println("公钥：" + publicKey);
        String privateKey = keyStore.getPrivateKey();
        // 设置RSA私钥
        apiConfig.setPrivateKey(privateKey);

        // 配置拦截器
        apiConfig.setInterceptors(
                new ApiInterceptor[] { new LogInterceptor()});

        apiConfig.addAppSecret(appSecretStore);
    }

}
